﻿namespace ExamV5.GradeInfo
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmCountUserAll : Page
    {
        protected Button butQuery;
        protected DropDownList DDLDept;
        protected DropDownList DDLUPDept;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private HttpCookie httpCookie_4 = null;
        protected Label labtableInfo;
        protected Label labTitle;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        protected TextBox txtEndDate;
        protected TextBox txtStartDate;
        protected UpdatePanel UPPart;

        protected void butQuery_Click(object sender, EventArgs e)
        {
            this.method_0();
        }

        protected void DDLDept_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.method_0();
        }

        protected void DDLUPDept_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DDLDept.Items.Clear();
            this.publicFun_0.LoadDeptInfo(this.DDLDept, this.DDLUPDept.SelectedItem.Value, this.httpCookie_0.Value, "B");
            if (this.DDLDept.Items.Count == 0)
            {
                if (!(this.DDLUPDept.SelectedItem.Value == "0"))
                {
                    ListItem item = new ListItem(this.DDLUPDept.SelectedItem.Text, this.DDLUPDept.SelectedItem.Value);
                    this.DDLDept.Items.Add(item);
                }
                else
                {
                    ListItem item2 = new ListItem("--所有部门--", "0");
                    this.DDLDept.Items.Insert(0, item2);
                }
            }
        }

        private void method_0()
        {
            int num = 1;
            string str = "";
            this.labtableInfo.Text = "";
            this.labTitle.Text = "";
            if (!((this.txtStartDate.Text.Trim() != "") ? !(this.txtEndDate.Text.Trim() != "") : true))
            {
                this.labTitle.Text = Convert.ToDateTime(this.txtStartDate.Text).ToLongDateString() + "—" + Convert.ToDateTime(this.txtEndDate.Text).ToLongDateString();
            }
            this.labTitle.Text = this.labTitle.Text + "〖" + this.DDLDept.SelectedItem.Text.Replace("│", "").Replace("├", "") + "〗考生综合统计分析表";
            str = ((((((((str + "<table cellSpacing='0' cellPadding='0' width='100%' align='center' border='1' bordercolordark='#cccccc' bordercolorlight='#cccccc'  bordercolor='#cccccc'  class='tableStyle'>" + "<tr height=30>") + "<td align='center' width=50><B>序号</b></td>" + "<td align='center' width=80><B>准考证号</b></td>") + "<td align='center' width=70><B>考生姓名</b></td>" + "<td align='center'><B>单位/部门名称</b></td>") + "<td align='center' width=60><B>所属职务</b></td>" + "<td align='center' width=70><B>应考次数</b></td>") + "<td align='center' width=70><B>实考次数</b></td>" + "<td align='center' width=90><B>累计总分</b></td>") + "<td align='center' width=70><B>平均得分</b></td>" + "<td align='center' width=90><B>学习任务总数</b></td>") + "<td align='center' width=70><B>参与数</b></td>" + "<td align='center' width=70><B>完成数</b></td>") + "<td align='center' width=70><B>未完成数</b></td>" + "<td align='center' width=70><B>未参与数</b></td>") + "<td align='center' width=90><B>总学分</b></td>" + "</tr>";
            string cmdText = "select a.UserCode,a.UserName,a.Worker,b.DeptName,a.DeptID,b.UPID from UserInfo a,DeptInfo b where a.DeptID=b.ID and a.Flag='A'";
            if (this.DDLDept.SelectedItem.Value != "0")
            {
                cmdText = cmdText + " and a.DeptID in (select b.ID from DeptInfo b where " + this.publicFun_0.GetManagDeptID(this.publicFun_0.CheckString(this.DDLDept.SelectedItem.Value)) + ")";
            }
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand(cmdText, connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            while (reader.Read())
            {
                str = (((str + "<tr height=25>") + "<td align='center' width=50>" + num.ToString() + "</td>") + "<td width=80>" + reader["UserCode"].ToString() + "</td>") + "<td width=70>" + reader["UserName"].ToString() + "</td>";
                if (!(reader["UPID"].ToString().Trim() == "0"))
                {
                    str = str + "<td>" + this.publicFun_0.GetValues("select DeptName from DeptInfo where ID=" + reader["UPID"].ToString().Trim(), "DeptName") + @"\" + reader["DeptName"].ToString().Trim() + "</td>";
                }
                else
                {
                    str = str + "<td>" + reader["DeptName"].ToString() + "</td>";
                }
                str = (((((((str + "<td width=60>" + reader["Worker"].ToString() + "</td>") + "<td align='center' width=70>" + this.method_2(reader["userCode"].ToString()) + "</td>") + this.method_1(reader["UserCode"].ToString())) + "<td align='center' width=90>" + this.method_3(reader["UserCode"].ToString(), "E") + "</td>") + "<td align='center' width=70>" + this.method_3(reader["UserCode"].ToString(), "A") + "</td>") + "<td align='center' width=70>" + this.method_3(reader["UserCode"].ToString(), "B") + "</td>") + "<td align='center' width=70>" + this.method_3(reader["UserCode"].ToString(), "C") + "</td>") + "<td align='center' width=70>" + this.method_3(reader["UserCode"].ToString(), "D") + "</td>";
                string strSql = "";
                strSql = "select Sum(a.StudyFen) as StudyFen from UserStudyFen a where a.UserCode='" + reader["UserCode"].ToString() + "'";
                if (this.txtStartDate.Text.Trim() != "")
                {
                    strSql = strSql + " and Convert(dateTime,a.InputDate)>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00')";
                }
                if (this.txtEndDate.Text.Trim() != "")
                {
                    strSql = strSql + " and Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')>=Convert(dateTime,a.InputDate)";
                }
                string values = this.publicFun_0.GetValues(strSql, "StudyFen");
                if (values.Trim() == "")
                {
                    values = "0";
                }
                str = (str + "<td align='center' width=90>" + values + "</td>") + "</tr>";
                num++;
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
            str = str + "</table>";
            this.labtableInfo.Text = str;
        }

        private string method_1(string string_0)
        {
            string str = "";
            string cmdText = "";
            cmdText = "select count(*) as ExamCount,ROUND(Sum(GetCountFen),2) as SumFen,ROUND(Sum(GetCountFen)/count(*),2) as AgeFen from ExamUser a where  a.UserCode='" + string_0 + "' and (a.Flag<>'A' and a.Flag<>'B') ";
            if (!(this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsLookTestExam'", "ParmValue").Trim() == "Y"))
            {
                cmdText = cmdText + " and  a.ExamType='A' ";
            }
            else
            {
                cmdText = cmdText + " and  (a.ExamType='A' or a.ExamType='C') ";
            }
            if (this.txtStartDate.Text.Trim() != "")
            {
                cmdText = cmdText + " and Convert(dateTime,a.JoinDate)>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00')";
            }
            if (this.txtEndDate.Text.Trim() != "")
            {
                cmdText = cmdText + " and Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')>=Convert(dateTime,a.JoinDate)";
            }
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand(cmdText, connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            if (reader.Read())
            {
                str = str + "<td align='center' width=70>" + reader["ExamCount"].ToString() + "</td>";
                if (!(reader["SumFen"].ToString().Trim() == ""))
                {
                    str = str + "<td align='center' width=90>" + reader["SumFen"].ToString() + "</td>";
                }
                else
                {
                    str = str + "<td align='center' width=90>0</td>";
                }
                if (!(reader["AgeFen"].ToString().Trim() == ""))
                {
                    str = str + "<td align='center' width=70>" + reader["AgeFen"].ToString() + "</td>";
                }
                else
                {
                    str = str + "<td align='center' width=90>0</td>";
                }
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
            if (str.Trim() == "")
            {
                str = (str + "<td align='center' width=70>0</td>") + "<td align='center' width=90>0</td>" + "<td align='center' width=70>0</td>";
            }
            return str;
        }

        private string method_2(string string_0)
        {
            string strSql = "";
            strSql = "select count(*) as ExamCount from ExamUser a where a.userCode='" + string_0 + "'";
            if (!(this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsLookTestExam'", "ParmValue").Trim() == "Y"))
            {
                strSql = strSql + " and  a.ExamType='A' ";
            }
            else
            {
                strSql = strSql + " and  (a.ExamType='A' or a.ExamType='C') ";
            }
            if (this.txtStartDate.Text.Trim() != "")
            {
                strSql = strSql + " and Convert(dateTime,a.JoinDate)>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00')";
            }
            if (this.txtEndDate.Text.Trim() != "")
            {
                strSql = strSql + " and Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')>=Convert(dateTime,a.JoinDate)";
            }
            return this.publicFun_0.GetValues(strSql, "ExamCount");
        }

        private string method_3(string string_0, string string_1)
        {
            string values = "0";
            switch (string_1)
            {
                case "A":
                    if ((this.txtStartDate.Text.Trim() != "") ? !(this.txtEndDate.Text.Trim() != "") : true)
                    {
                        values = this.publicFun_0.GetValues("select  Count(*) as CountInfo from  StudyPlanInfo a,StudyUser b where b.LoginIP<>'' and  b.UserCode='" + string_0 + "' and a.ID=b.PlanID ", "CountInfo");
                    }
                    else
                    {
                        values = this.publicFun_0.GetValues("select  Count(*) as CountInfo from  StudyPlanInfo a,StudyUser b where b.LoginIP<>'' and b.UserCode='" + string_0 + "' and a.ID=b.PlanID and a.InputTime>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00') and a.InputTime<=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')", "CountInfo");
                    }
                    break;

                case "B":
                    if (!((this.txtStartDate.Text.Trim() != "") ? !(this.txtEndDate.Text.Trim() != "") : true))
                    {
                        values = this.publicFun_0.GetValues("select  Count(*) as CountInfo from  StudyPlanInfo a,StudyUser b where b.LoginIP<>'' and a.StudyLongTime*60<=b.CountTime and b.UserCode='" + string_0 + "' and a.ID=b.PlanID and a.InputTime>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00') and a.InputTime<=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')", "CountInfo");
                    }
                    else
                    {
                        values = this.publicFun_0.GetValues("select  Count(*) as CountInfo from  StudyPlanInfo a,StudyUser b where b.LoginIP<>'' and a.StudyLongTime*60<=b.CountTime and  b.UserCode='" + string_0 + "' and a.ID=b.PlanID ", "CountInfo");
                    }
                    break;

                case "C":
                    if (!(this.txtStartDate.Text.Trim() != "") || !(this.txtEndDate.Text.Trim() != ""))
                    {
                        values = this.publicFun_0.GetValues("select  Count(*) as CountInfo from  StudyPlanInfo a,StudyUser b where b.LoginIP<>'' and a.StudyLongTime*60>b.CountTime and  b.UserCode='" + string_0 + "' and a.ID=b.PlanID ", "CountInfo");
                    }
                    else
                    {
                        values = this.publicFun_0.GetValues("select  Count(*) as CountInfo from  StudyPlanInfo a,StudyUser b where b.LoginIP<>'' and a.StudyLongTime*60>b.CountTime and b.UserCode='" + string_0 + "' and a.ID=b.PlanID and a.InputTime>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00') and a.InputTime<=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')", "CountInfo");
                    }
                    break;

                case "D":
                    if (!((this.txtStartDate.Text.Trim() != "") ? !(this.txtEndDate.Text.Trim() != "") : true))
                    {
                        values = this.publicFun_0.GetValues("select  Count(*) as CountInfo from  StudyPlanInfo a,StudyUser b where b.LoginIP='' and b.UserCode='" + string_0 + "' and a.ID=b.PlanID and a.InputTime>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00') and a.InputTime<=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')", "CountInfo");
                    }
                    else
                    {
                        values = this.publicFun_0.GetValues("select  Count(*) as CountInfo from  StudyPlanInfo a,StudyUser b where b.LoginIP='' and  b.UserCode='" + string_0 + "' and a.ID=b.PlanID ", "CountInfo");
                    }
                    break;

                case "E":
                    if ((this.txtStartDate.Text.Trim() != "") ? !(this.txtEndDate.Text.Trim() != "") : true)
                    {
                        values = this.publicFun_0.GetValues("select  Count(*) as CountInfo from  StudyPlanInfo a,StudyUser b where b.UserCode='" + string_0 + "' and a.ID=b.PlanID ", "CountInfo");
                    }
                    else
                    {
                        values = this.publicFun_0.GetValues("select  Count(*) as CountInfo from  StudyPlanInfo a,StudyUser b where b.UserCode='" + string_0 + "' and a.ID=b.PlanID and a.InputTime>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00') and a.InputTime<=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')", "CountInfo");
                    }
                    break;
            }
            if (values.Trim() == "")
            {
                values = "0";
            }
            return values;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            this.httpCookie_4 = new HttpCookie("ExamDeptName");
            this.httpCookie_4 = base.Request.Cookies["ExamDeptName"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.httpCookie_4.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_4.Value));
                this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "---考生综合报表分析";
                if (!base.IsPostBack)
                {
                    if (this.publicFun_0.ReturnPaperData() == "Yes")
                    {
                        if (this.httpCookie_2.Value != "A")
                        {
                            this.DDLUPDept.DataTextField = "DeptName";
                            this.DDLUPDept.DataValueField = "ID";
                            if (!(this.httpCookie_2.Value == "C"))
                            {
                                this.DDLUPDept.DataSource = this.publicFun_0.RetrunDataView("select ID,DeptName from DeptInfo where ID=" + this.httpCookie_3.Value + " order by SortInfo,ID");
                            }
                            else
                            {
                                this.DDLUPDept.DataSource = this.publicFun_0.RetrunDataView("select ID,DeptName from DeptInfo where UPID=0  order by SortInfo,ID");
                            }
                            this.DDLUPDept.DataBind();
                            if (this.httpCookie_2.Value == "C")
                            {
                                this.DDLUPDept.SelectedIndex = -1;
                                this.DDLDept.SelectedIndex = -1;
                                ListItem item2 = new ListItem("--所有单位--", "0");
                                ListItem item3 = new ListItem("--所有部门--", "0");
                                this.DDLDept.Items.Insert(0, item3);
                                this.DDLUPDept.Items.Insert(0, item2);
                            }
                            else
                            {
                                this.DDLDept.Items.Clear();
                                this.publicFun_0.LoadDeptInfo(this.DDLDept, this.DDLUPDept.SelectedItem.Value, this.httpCookie_0.Value, "B");
                                if (this.DDLDept.Items.Count == 0)
                                {
                                    ListItem item = new ListItem(this.DDLUPDept.SelectedItem.Text, this.DDLUPDept.SelectedItem.Value);
                                    this.DDLDept.Items.Add(item);
                                }
                            }
                            this.method_0();
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckA", "alert('考生综合报表分析权限未开放！')", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')", true);
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

